using System;
using System.Collections.Generic;

namespace SilenthinkContract.Domain
{
    /// <summary>
    /// 订单
    /// </summary>
    public class Order : Versionable<string>
    {
        #region Properties

        public int UserId { get; set; }
        public OrderCategory Category { get; set; }
        public int Quantity { get; set; }
        public decimal SubTotal { get; set; }
        public decimal ShippingCharge { get; set; }
        public decimal Discount { get; set; }
        public decimal Total { get; set; }
        public decimal Paid { get; set; }
        public decimal Refunded { get; set; }
        public decimal Weight { get; set; }
        public string TraceCode { get; set; }
        public byte ShippingMethod { get; set; }
        public byte PaymentMethod { get; set; }
        public DateTime? PaidDate { get; set; }
        public DateTime? ShippingDate { get; set; }
        public DateTime? DeliveryDate { get; set; }
        public OrderStatus OrderStatus { get; set; }
        public ShippingStatus ShippingStatus { get; set; }
        public PaymentStatus PaymentStatus { get; set; }
        public DateTime Expiration { get; set; }
        public string AreaCode { get; set; }
        public string IpAddress { get; set; }
        public string AssociatedId { get; set; }

        #endregion

        #region Navigation Properties

        /// <summary>
        /// 订单扩展信息
        /// </summary>
        public virtual OrderExtra OrderExtra { get; set; }

        /// <summary>
        /// 订单明细
        /// </summary>
        public virtual IList<OrderItem> OrderItems { get; set; }

        /// <summary>
        /// 订单备注
        /// </summary>
        public virtual IList<OrderNote> OrderNotes { get; set; }

        /// <summary>
        /// 订单使用的折扣
        /// </summary>
        public virtual IList<DiscountUsageHistory> DiscountUsageHistory { get; set; }

        ///// <summary>
        ///// 订单使用的礼品卡
        ///// </summary>
        //public virtual IList<GiftCardUsageHistory> GiftCardUsageHistory { get; set; }

        #endregion

        public UserTrade ToTrade()
        {
            var trade = new UserTrade();
            var title = string.Empty;
            trade.Id = Id;
            trade.UserId = UserId;
            trade.Title = title;
            trade.Category = 0;/*交易类型 0为购物 1为代充 代付等*/
            trade.FundFlow = 0;/*资金流转 1为收入 0为支出*/
            trade.Amount = Total;/*交易金额*/
            trade.Paid = 0;/*已支付金额(一个订单可能分多次支付)*/
            trade.Refunded = 0;/*退款金额*/
            trade.ForUserId = 0;
            trade.ForUserName = string.Empty;
            trade.AssistNo = string.Empty;
            trade.Extra = string.Empty;/*扩展信息*/
            trade.Status = UserTradeStatus.Pending;/*交易状态 0为成功 1为待支付 2为失败*/
            trade.CreatedBy = string.Empty;
            trade.CreatedOn = DateTime.Now;
            return trade;
        }
    }
}